<?php

/**
 *  @FileComment            [前台注册控制器]
 *  @ProjectName             项目名称：ShopFrame
 *  @FileName                   文件名称：RegisterController.class.php
 *  @Author                       yuerengui <596580041@qq.com>
 *  @Date                          2014-10-4 21:46:14
 *  *
 */
class RegisterController extends Controller {

        private $model;

        public function __init() {
                $this->model = K('User');
        }

        public function index() {
                $this->display();
        }

        public function code() {
                $code = new Code();
                $code->show();
        }

        public function code_check() {
                //验证码异步验证
                $code = Q('get.code', 0, 'strtoupper');
                if ($code == session('code')) {
                        echo 1;
                } else {
                        echo 0;
                }die;
        }

        public function user_check() {
                //用户异步验证
                $username = Q('get.username', '');
                $data = $this->model->where(array('username' => $username))->find();
                if (!empty($data)) {
                        echo 0;
                } else {
                        echo 1;
                }die;
        }

        public function check() {
                $tempArr = array();
                if ($this->model->create() && $this->model->add_user()) {
                        $tempArr['success'] = 1;
                        $tempArr['url'] = U('Register/success_reg');
                } else {
                        $tempArr['success'] = 0;
                        $tempArr['error'] = $this->model->error;
                }
                $this->ajax($tempArr);
        }

        public function success_reg() {
                $this->display();
        }

}
